package com.example.myapplication.tack_06;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_06.data.BookSXQData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

public class BooksXQ extends AppCompatActivity {
    private ImageView eixt;
    private String id;
    private ImageView imags;
    private TextView  name;
    private TextView  address;
    private TextView  businessHours;
    private TextView  businessState;
    private TextView  description;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_06_books_x_q);
        init();
        eixt_();
        Intent intent = getIntent();
        id = intent.getStringExtra(Common.COMMON);
        getXQ(id);
    }

    private void getXQ(String id) {
        String url = "prod-api/api/digital-library/library/"+id;
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, BookSXQData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                BookSXQData bookSXQData = (BookSXQData)obj;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        XQAdapter(bookSXQData);
                    }
                });
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void XQAdapter(BookSXQData bookSXQData) {
        Glide.with(BooksXQ.this).load(OkHttpTool.URL+bookSXQData.getData().getImgUrl()).into(imags);
        name.setText(bookSXQData.getData().getName());
        address.setText(bookSXQData.getData().getName());
        businessHours.setText(bookSXQData.getData().getBusinessHours());
        if("1".equals(bookSXQData.getData().getBusinessState())){
            businessState.setText("营业中");
        }else if("0".equals(bookSXQData.getData().getBusinessState())){
            businessState.setText("打样");
        }

        description.setText("简介:\n"+"    "+bookSXQData.getData().getDescription());
    }

    private void eixt_() {
        eixt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BooksXQ.this.finish();
            }
        });
    }

    private void init() {
        eixt = findViewById(R.id.exit);
        imags = findViewById(R.id.imags);
        name = findViewById(R.id.name);
        address = findViewById(R.id.address);
        businessHours = findViewById(R.id.businessHours);
        businessState = findViewById(R.id.businessState);
        description = findViewById(R.id.description);
    }
}